--
-- Author: yawei.zhu
-- Date: 2018-09-11 20:09:54
--
-- DynastyBattleMapRender
--

local ClassRef = app.mvc.createRenderClass(...)

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.DynastyBattleMapItem))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)

    self._ui.map_img:setVisible(false)
    self._ui.img:setTouchEnabled(false)
    self._ui.Panel:addClickEventListener(function()
        executeFunc(self._onClick, self._index)
    end)

    self:refresh()
end

function ClassRef:refresh()
    if not self._data then return end

    self._index = self._data.index

    if self._data.color == "bule" then
        self._ui.q_blue:setVisible(true)
        self._ui.q_red:setVisible(false)
    else -- red
        self._ui.q_blue:setVisible(false)
        self._ui.q_red:setVisible(true)
    end
end

function ClassRef:setSelected(flag)
    self._ui.light:setVisible(flag)
    self._ui.star:setVisible(flag)
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef
